package com.sofa.logging.service;

import com.sofa.logging.entity.Log;
import com.sofa.logging.mapper.LogMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.function.Consumer;

@Service
@RequiredArgsConstructor
@Slf4j
public class LogService {

    private final LogMapper logMapper;

    @Bean
    public Consumer<String> handleMessage() {
        return message -> {
            log.info("Received log message: {}", message);
            Log logEntry = new Log();
            logEntry.setContent(message);
            logEntry.setCreateTime(LocalDateTime.now());
            logMapper.insert(logEntry);
        };
    }
} 